;;; simple wrappers for generating random values

(in-package #:experiment)

(defun randomize (seed)
  (setf mt19937:*random-state* (mt19937::make-random-object :state (mt19937:init-random-state seed))))

(defun randomize-timer ()
  (let ((seed (logand (get-internal-run-time) #xffffffff)))
    (values (randomize seed) seed)))

(defun random (max &optional (state mt19937:*random-state*))
  (assert (mt19937:random-state-p state)
          ()
          "Use RANDOMIZE or RANDOMIZE-TIMER to create a random state.")
  (mt19937:random max state))

;; We don't want mt19937:random to be called until we have properly
;; set the random state with one of the above functions.
(eval-when (:load-toplevel :execute)
  (setf mt19937:*random-state* nil))
